Skip to content

fix: show the phone's opened comment sooner, and skip hidden comments in its swipe - #324

Merged
therealsama merged 5 commits into
mainfrom
fix/phone-comment-swipe-hidden-siblings
Nov 5, 2026
Merged

therealsama merged 5 commits into
mainfrom
fix/phone-comment-swipe-hidden-siblings

Conversation

@therealsama

@therealsama therealsama commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Follow-up to #323, which dropped the first version of the hidden-comment fix because it held up the opened comment on large threads. In this version nothing waits for the hidden-comment check. It also fixes a retry bug in the same viewer.

Changes

  • After a retry, the phone's comment viewer showed the first sibling. When a comment's siblings failed to load, the viewer still started the swipe, on the one-comment list the failed load left. When the automatic retry brought the siblings in, the viewer showed the first of them and moved the URL there, away from the comment that was opened. The swipe now starts only once the siblings load without an error.
  • The opened comment waited for the sibling list. The viewer showed a skeleton until it had read the comment and its parent from Firebase, and only then started loading the comment. The comment now shows as the only panel while its siblings load. Once they're in, the swipe starts on that same panel: it isn't mounted or fetched again, and keeps the reader's place in it. useSwipeScroll gets resetToIndex for this, which switches to the new list without moving the page. While the siblings retry, the comment stays on screen instead of a skeleton.
  • The swipe landed on comments the thread hides. It takes its comments from the parent's kids, which include deleted and flagged comments with nothing under them. HN and the thread leave those out (see fix: show flagged replies on a comment's page, and two smaller fixes #321). Across the top 15 stories, 29 of 357 top-level comments were such comments. Swiping onto a deleted one showed "Comment deleted" with no links, and swiping onto a flagged one showed [flagged] with its author. Once the list is in, the viewer reads every sibling from Firebase. The swipe then passes over the flagged and deleted ones with no replies, the rule the comment page's reply check uses. It never passes over the comment it was opened on, or one whose read fails. Those panels stay in the list, so the reads don't hold up the swipe, and a swipe already under way keeps its target. The panels loaded ahead on each side are now the swipe's next stops rather than the nearest panels.

Measurements

"Ask HN: Who wants to be hired? (November 2026)" has 438 top-level comments. These numbers come from opening the 41st with a Pixel 7 profile, from the time the page opens, two runs each:

main this PR
Comment shown 1.20–1.24s 0.79–0.97s
Comment shown, slow 4G 2.71–2.80s 2.26–2.36s
Swipe ready 0.90–0.95s 0.88–0.91s
Swipe ready, slow 4G 2.45–2.52s 2.46–2.51s
Last Firebase frame 1.37–1.45s 1.47–1.49s
Last Firebase frame, slow 4G 3.14–3.25s 7.40–7.47s
Firebase data 51KB 670KB

The sibling reads make up the last Firebase frames here, so hidden comments are skipped from about that point. On the same thread, one swipe forward from 50364051 on main landed on 50362176, "Comment deleted". With this PR it lands on 50362186, the next live comment.

Known limitations

  • Until the sibling reads finish, a swipe can still land on a hidden comment. On the largest threads over slow 4G, that's the first 7 seconds or so.
  • The reads fetch each sibling whole: about 620KB on that thread, each time a comment is opened from outside the swipe. Reading only dead, deleted and kids would cut that, at three reads per sibling.
  • If the siblings still fail after the retries, "Failed to load comments" replaces the comment, as it replaced the skeleton before.
  • A deleted comment whose replies are all hidden still counts as having replies, so the swipe still stops on it. The comment page's reply check counts it the same way.

When a comment's siblings failed to load, the viewer still started the
swipe, on the one-comment list the failed load left. The automatic
retry then brought in the siblings, but with the swipe already started
the viewer showed the first of them and moved the URL there, away from
the comment that was opened. The swipe now starts only once the
siblings load without an error.
The swipe comment viewer showed a skeleton until it had read the comment
and its parent from Firebase for the sibling list, and only then started
loading the comment itself. The comment now shows as the only panel
while the siblings load, and loads alongside them. Once they're in, the
swipe starts on that same panel: it stays mounted, isn't fetched again,
and keeps the reader's place in it. useSwipeScroll gets `resetToIndex`
for this, which switches to the new list without moving the page. While
the siblings retry after a failed load, the comment stays on screen
instead of a skeleton.

On "Ask HN: Who wants to be hired? (November 2026)" a comment now shows
after 0.8-1.0s instead of 1.2s, or 2.3s instead of 2.7-2.8s on slow 4G.
The swipe is ready when it was before.
The swipe comment viewer took its comments from the parent's `kids` in
Firebase, which include deleted and flagged comments that the thread,
like HN, leaves out when nothing is under them. Across the top 15
stories, 29 of 357 top-level comments were such comments, and so are 29
of the 438 on "Ask HN: Who wants to be hired?". Swiping onto a deleted
one showed "Comment deleted" with no parent or story link. Swiping onto
a flagged one showed "[flagged]" with its author.

Once the list is in, the viewer reads every sibling from Firebase, and
the swipe passes over the flagged and deleted ones with no replies, the
rule the comment page's reply check uses. It never passes over the
comment it was opened on, or one whose read fails. Those panels stay in
the list, so the reads don't hold up the swipe, and a swipe under way
keeps its target. The panels loaded ahead on each side are now the
swipe's next stops rather than the nearest panels.

On "Who wants to be hired?" the swipe starts when it did before, and
passes over hidden comments from about 1.5s after the page opens, or
7.4s on slow 4G. A swipe before then can still land on one. The reads
add about 620KB.
The phone's comment viewer swaps everything for "Failed to load
comments" when its siblings failed to load and `isRetrying` is off. That
flag is still off in the render where a load fails, and only comes on in
a layout effect after it. So each failure rendered the error branch once,
before paint, which unmounted the panels: the comment shown while its
siblings load was mounted again, fetched again, and lost the reader's
place. Scrolled 600px down it, a reader dropped to 27px in Mobile Chrome
and 207px in Mobile Safari at the first failed retry.

The viewer now shows the error once the retries have given up, as
`SwipeStoryViewer` does. That is the only time the error showed on
screen before, so offline, after giving up and on a manual retry it
shows as it did.
@therealsama
therealsama enabled auto-merge November 5, 2026 18:21
@therealsama
therealsama merged commit e8c2252 into main Nov 5, 2026
4 checks passed
@therealsama
therealsama deleted the fix/phone-comment-swipe-hidden-siblings branch November 5, 2026 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants